<?php
namespace app\wechat\controller;
use app\wechat\service\Open;
use app\wechat\traits\Official;
use EasyWeChat\Factory;
use think\Controller;
use think\Request;

class Test extends Controller
{
    use Official;
    //微信wang登录
    public function syslogin()
    {
        $res = $this->login(url('document/home.index/index'),url("wechat/test/testcallback"));
        if(is_array($res))
        {
            dump($res);
        }else{
            $res->setStatusCode(301)->send();

        }
    }

    public function testcallback()
    {
        $config = get_option("wechat_official");
        $config = array_merge($config['official'],config("official."));
        $app    = Factory::officialAccount($config);
        $oauth  = $app->oauth;
        $user = $oauth->user();
        halt($user);
    }


    public function minprogram(Request $request)
    {
        $code = $request->post("code");
        if(!$code) $this->error("请输入code");
        $res = $this->SmallProgramLogin($code);


        return json($res);
      /*  if(isset($res['openid']))
        {
            $this->success('success:','',$res);
        }else{
            $this->error('error:','',$res);
        }*/
    }

    /**
     * Notes:微信授权登陆
     * User: chenping
     * email: 375129701@qq.com
     */
    public function wechatlogin()
    {
        $config = get_option("wechat_official");
        $service = new Open($config['open']);
         $service->oauth();
    }
}